package procsim;

public class TFlipFlop extends FlipFlop{
    private Signal inSig;
    public TFlipFlop(Signal in){
        super();
        if(in!=null) in.addElement(this);
        inSig=in;
    }
    public TFlipFlop(){
        super();
    }
    public TFlipFlop setTSignal(Signal tsig){
        if(tsig!=null) tsig.addElement(this);
        inSig=tsig;
        return this;
    }
    @Override
    public TFlipFlop tick(){
        outSig.set(outSigPrev);
        if(outSigResult!=null) outSigResult.set(outSig);
        if(inSig!=null) outSigPrev.set(inSig.get()^outSigPrev.get());
        calculateComplement();
        return this;
    }
    @Override
    public void updateSignal(Sig sig){
        if(ticking) return;
        if(inSig!=null && inSig==sig)
            inSig.set(sig.get(), false);
    }
}
